package kr.or.kead.ui;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionListener;
import java.awt.event.KeyListener;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTable;
import kr.or.kead.service.DaoTable;
import kr.or.kead.ui.font.FontClass;
import kr.or.kead.ui.list.AbsTablelist;

public abstract class AbsView extends JPanel implements ActionListener, KeyListener {
	protected JPanel topPanel, bottomPanel, btnPanel;
	private GridBagLayout gbl;
	private GridBagConstraints gbc;
	protected Container contentPane;
	protected FontClass font;
	protected JFrame frame;
	protected AbsTablelist list;
	protected String title;
	protected DaoTable daoTable;
	protected int selectRowCount;
	protected JTable table;
	protected String selectCode;
	protected int saveUpdateFlag;
	protected int frameHeight;
	public AbsView(JFrame frame,  String title) {
		this.frame = frame;
		this.title = title;
		initialize();
	}
	protected void initialize() {
		frame.setTitle(title);
		setLayout(new BorderLayout());
		contentPane = frame.getContentPane();
		contentPane.removeAll();
		gbl = new GridBagLayout();
		font = new FontClass();		
		topPanel = new JPanel(gbl);
		bottomPanel = new JPanel(new BorderLayout());
		btnPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 5));
		createTopPanel();
		createBottomPanel();
		add(topPanel, BorderLayout.NORTH);
		add(bottomPanel, BorderLayout.CENTER);
		contentPane.add(this);
		contentPane.validate();		
	}

	protected void gridSet(Component c, int x, int y, int w, int h) {
		gbc = new GridBagConstraints();
		gbc.fill = GridBagConstraints.BOTH;
		gbc.insets = new Insets(2, 2, 5, 5);
		gbc.gridx = x;
		gbc.gridy = y;
		gbc.gridheight = h;
		gbc.gridwidth = w;
		gbl.setConstraints(c, gbc);
		topPanel.add(c);
	}

	public void refreshList(AbsTablelist list) {
		Container contentPane = frame.getContentPane();
		contentPane.removeAll();
		list.setTableModel();
		contentPane.add(this);
		contentPane.validate();
//		frame.pack();
	}



	protected abstract void createTopPanel();
	protected abstract void createBottomPanel();
	protected abstract int regexValue();


}
